package com.hksj.cm.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hksj.cm.dto.ParticleLevelSettingDTO;
import com.hksj.cm.entity.ParticleLevelSetting;
import com.hksj.cm.mapper.ParticleLevelSettingMapper;
import com.hksj.cm.vo.ConstructionStandardsVO;
import com.hksj.cm.vo.ParticleLevelSettingVO;
import com.hksj.common.core.model.Rest;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import springfox.documentation.swagger2.mappers.ModelMapper;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName ParticleLevelSettingService
 * @Description TODO
 * @Author @陈章
 * @Date 2024/7/23 17:57
 * @Version 1.0
 */
@Service
public class ParticleLevelSettingService extends ServiceImpl<ParticleLevelSettingMapper, ParticleLevelSetting> {

    @Autowired
    private ParticleLevelSettingMapper mapper;

    public Rest<String> createParticleLevelSetting(List<ParticleLevelSettingDTO> list) {
        for (ParticleLevelSettingDTO particleLevelSettingDTO : list) {
            ParticleLevelSetting particleLevelSetting = new ParticleLevelSetting();
            BeanUtils.copyProperties(particleLevelSettingDTO, particleLevelSetting);
            boolean b = this.saveOrUpdate(particleLevelSetting);
            if (!b) {
                Rest.fail("新增失败");
            }
        }

        return Rest.ok("新增成功");
    }

    public List<ParticleLevelSettingVO> selectParticleLevelSettingList() {
        List<ParticleLevelSetting> sourceList = list();
        List<ParticleLevelSettingVO> targetList = sourceList.stream()
                .map(setting -> new ParticleLevelSettingVO(
                        setting.getId(),
                        setting.getParticleValue(),
                        setting.getChoose()))
                .collect(Collectors.toList());
        return targetList;
    }
}
